# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gmp
pkgver=6.3.0
pkgrel=0
pkgdesc="free library for arbitrary precision arithmetic"
url="https://gmplib.org/"
arch="all"
license="LGPL-3.0-or-later OR GPL-2.0-or-later"
makedepends="m4 texinfo libtool autoconf automake"
subpackages="$pkgname-doc $pkgname-dev libgmpxx"
source="https://gmplib.org/download/gmp/gmp-$pkgver.tar.xz"
replaces="gmp5"

# secfixes:
#   6.2.1-r1:
#     - CVE-2021-43618

# lto is not available during bootstrap
if [ -z "$BOOTSTRAP" ]; then
        _lto_cflags="-flto=auto"
fi

prepare() {
	default_prepare
	# force update to libtool with fixed cross-build support
	autoreconf -vif
}

build() {
	CFLAGS="$CFLAGS $_lto_cflags" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--with-sysroot=$CBUILDROOT \
		--prefix=/usr \
		--infodir=/usr/share/info \
		--mandir=/usr/share/man \
		--localstatedir=/var/state/gmp \
		--enable-cxx \
		--with-pic
	make
}

check() {
	[ "$CBUILD" = "$CHOST" ] && make check
}

package() {
	make DESTDIR="$pkgdir" install
}

libgmpxx() {
	pkgdesc="C++ support for gmp"
	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libgmpxx.so.* "$subpkgdir"/usr/lib/
}

doc() {
	default_doc
	replaces="gmp5-doc"
}

sha512sums="
e85a0dab5195889948a3462189f0e0598d331d3457612e2d3350799dba2e244316d256f8161df5219538eb003e4b5343f989aaa00f96321559063ed8c8f29fd2  gmp-6.3.0.tar.xz
"
